package com.genesis.web.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.genesis.mall.common.Result;
import com.genesis.mall.entity.PmsProduct;
import com.genesis.mall.entity.PmsSkuStock;
import com.genesis.mall.service.IPmsSkuStockService;
import com.genesis.mall.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * sku的库存 前端控制器
 * </p>
 *
 * @author author
 * @since 2022-08-01
 */
@RestController
@RequestMapping("/sku")
@Slf4j
public class PmsSkuStockController {

    @Autowired
    private IPmsSkuStockService pmsSkuStockService;

    @GetMapping("/{productId}")
    public Result<List<PmsSkuStock>> getSku(@PathVariable Long productId,  String keyword){
        log.info("根据id获取sku的库存");
        LambdaQueryWrapper<PmsSkuStock> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PmsSkuStock::getProductId,productId).eq(StringUtils.isNotEmpty(keyword),PmsSkuStock::getSkuCode,keyword);
        List<PmsSkuStock> list = pmsSkuStockService.list(queryWrapper);

        return Result.success(list);
    }
}
